package com.example.qixinshangwutong.view.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.qixinshangwutong.R;

public class NewsActivity extends AppCompatActivity {
    private ImageView companySearch;
    private WebView webview;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news);
        initView();
    }

    private void initView() {
        ImageView img=findViewById(R.id.img);
        WebView webview = findViewById(R.id.news_name);
        TextView textView=findViewById(R.id.text_view);
        Intent intent3 = getIntent();
        if (intent3.getExtras() != null) {
            String uri = intent3.getExtras().getString("uri");
            String name=intent3.getExtras().getString("name");
            textView.setText(name);
            webview.loadUrl(uri);
            webview.setWebViewClient(new WebViewClient() {
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                    view.loadUrl(request.getUrl().toString());
                    return true;
                }

            });
            webview.setWebChromeClient(new WebChromeClient() {
                @Override
                public void onProgressChanged(WebView view, int newProgress) {
                    super.onProgressChanged(view, newProgress);


                }
            });
            webview.getSettings().setJavaScriptEnabled(true);
            webview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        }
        else {
            Toast.makeText(NewsActivity.this,"加载超时请重试！",Toast.LENGTH_SHORT).show();
        }
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                NewsActivity.this.finish();
            }
        });
    }
}